package org.example.service.impl;

import org.example.Mapper.ActivityMapper;
import org.example.domain.Activity;
import org.example.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public void addActivity(Activity activity) {
        activityMapper.addActivity(activity.getName(),activity.getDate(),activity.getAddress(),activity.getPicture(),
                activity.getContent(),activity.getMax(),activity.getMax(),activity.getEmcee(),activity.getTheme(),
                activity.getEmceeInfo(),activity.getScreenType(), Integer.valueOf(activity.getTag()));
    }//上架一项活动

    /**
     * 更新一项活动信息
     * @param activity
     */
    @Override
    public void updateActivityInfoById(Activity activity) {
        activityMapper.updateActivityInfoById(activity.getName(),activity.getContent(),activity.getId(),
                activity.getEmcee(), activity.getTheme(), activity.getEmceeInfo(), Integer.valueOf(activity.getTag()));
    }

    @Override
    public Activity[] getActivitiesByIsOver(int start) {
        Activity[] activities;
        activities=activityMapper.getActivitiesByIsOver(start);
        for (Activity activity : activities) {//进行活动分类
            switch (activity.getTag()){
                case "0":
                    activity.setTag("思政培根");
                    break;
                case "1":
                    activity.setTag("学科启智");
                    break;
                case "2":
                    activity.setTag("体育强魄");
                    break;
                case "3":
                    activity.setTag("美育润心");
                    break;
                case "4":
                    activity.setTag("劳动强基");
                    break;
                case "5":
                    activity.setTag("创新创业");
                    break;
                case "6":
                    activity.setTag("其他");
                    break;
                default:
                    activity.setTag("未分类");
            }
        }
        return activities;
    }

    @Override
    public Activity getActivityById(Integer id) {
        return activityMapper.getAllById(id);
    }

    @Override
    public Activity[] getActivitiesByName(String name) {
        name="%"+name+"%";//模糊匹配
        return activityMapper.getActivitiesByName(name);
    }

    /**
     * 根据名称和标签查询，标签可不传
     */
    @Override
    public Activity[] getActivitiesByNameButNoPicture(String name,Integer tag) {
        name="%"+name+"%";//模糊匹配
        if(tag==null){

        } else if(tag==7){//7表示全查
            tag=null;
        }
        Activity[] activities;
        activities=activityMapper.getActivitiesByNameButNoPicture(name,tag);
        for (Activity activity : activities) {//进行活动分类
            switch (activity.getTag()){
                case "0":
                    activity.setTag("思政培根");
                    break;
                case "1":
                    activity.setTag("学科启智");
                    break;
                case "2":
                    activity.setTag("体育强魄");
                    break;
                case "3":
                    activity.setTag("美育润心");
                    break;
                case "4":
                    activity.setTag("劳动强基");
                    break;
                case "5":
                    activity.setTag("创新创业");
                    break;
                case "6":
                    activity.setTag("其他");
                    break;
                default:
                    activity.setTag("未分类");
            }
        }
        return activities;
    }

    @Override
    public Activity[] getActivitiesByNameAndIsOver(String name) {
        name="%"+name+"%";//模糊匹配
        return activityMapper.getActivitiesByNameAndIsOver(name);
    }

    @Override
    public void downActivityById(Integer id) {
        activityMapper.downActivityById(id);
    }

}
